import axios from 'axios';
import { setupInterceptor } from './interceptors.js';
import { config } from './config'

function createAxios(option = {}, hasInterceptor = true) {
  const defBaseURL = window.__APP__GLOB__CONF__?.VITE_BASE_URL || import.meta.env.VITE_BASE_URL;
  const defaultOptions = Object.assign(
    {
      timeout: 120000,
      baseURL: defBaseURL,
    },
    option,
  );
  const service = axios.create(defaultOptions);
  hasInterceptor && setupInterceptor(service);
  return service;
}

export const defaultAxios = createAxios(null);

defaultAxios.setBaseUrl = (baseUrl) => {
	defaultAxios.defaults.baseURL = baseUrl;
}

defaultAxios.getBaseUrl = () => {
	return defaultAxios.defaults.baseURL;
}

export const fileAxios = createAxios(null, false);
